<!DOCTYPE html>
<html>
    <head>
        <script src="http://innatedb.com/js/jquery/jquery-1.9.1.js"></script>
        <link href="http://innatedb.com/plugins/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <script src="http://innatedb.com/plugins/bootstrap/js/bootstrap.js"></script>

        <script type="text/javascript" src="http://innatedb.com/js/cytoscape/cerebral.js"></script>
        <script type="text/javascript" src="http://innatedb.com/js/cytoscape/cytoscape.min.js"></script>
        <script type="text/javascript" src="http://innatedb.com/js/cytoscape/layout.horizontal.js"></script>

    </head>
    <body>
        <div class="row-fluid">
            <div class="span12" style="height:400px" id="cy"></div>
        </div>

        <script type="text/javascript">
            function replaceAll(find, replace, str) {
                var re = new RegExp(find, 'g');
                str = str.replace(re, replace);
                return str;
            }
            var genes = {"ENSG00000127445": "PIN1",
                "ENSG00000171603": "CLSTN1",
                "ENSG00000103266": "STUB1",
                "ENSG00000158747": "NBL1",
                "ENSG00000148082": "SHC3",
                "ENSG00000160691": "SHC1",
                "ENSG00000214575": "CPEB1",
                "ENSG00000075711": "DLG1",
                "ENSG00000067113": "PPAP2A",
                "ENSG00000084234": "APLP2",
                "ENSG00000142192": "APP",
                "ENSG00000106772": "PRUNE2",
                "ENSG00000034053": "APBA2",
                "ENSG00000133961": "NUMB",
                "ENSG00000117758": "STX12",
                "ENSG00000132535": "DLG4",
                "ENSG00000121653": "MAPK8IP1",
                "ENSG00000163697": "APBB2",
                "ENSG00000128564": "VGF",
                "ENSG00000169783": "LINGO1",
                "ENSG00000173406": "DAB1",
                "ENSG00000008735": "MAPK8IP2",
                "ENSG00000145335": "SNCA",
                "ENSG00000196549": "MME",
                "ENSG00000100083": "GGA1",
                "ENSG00000138449": "SLC40A1",
                "ENSG00000153071": "DAB2",
                "ENSG00000150991": "UBC",
                "ENSG00000105290": "APLP1",
                "ENSG00000111344": "RASAL1",
                "ENSG00000103769": "RAB11A",
                "ENSG00000186318": "BACE1",
                "ENSG00000113108": "APBB3",
                "ENSG00000166313": "APBB1",
                "ENSG00000171867": "PRNP",
                "ENSG00000162604": "TM2D1"};
            
            var ensemblIds = replaceAll('"', '', JSON.stringify(Object.keys(genes)).replace('\[', '').replace('\]', ''));

            var edges =[{"data": {"id": "375184", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000160691", "idgroup": "375184"}, "group": "edges"},
                        {"data": {"id": "367978", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000105290", "idgroup": "367978"}, "group": "edges"},
                        {"data": {"id": "26032", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000169783", "idgroup": "26032"}, "group": "edges"},
                        {"data": {"id": "367969", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000145335", "idgroup": "367969"}, "group": "edges"},
                        {"data": {"id": "367972", "name": "interologs mapping", "source": "ENSG00000008735", "target": "ENSG00000142192", "idgroup": "367972"}, "group": "edges"},
                        {"data": {"id": "367968", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000103266", "idgroup": "367968"}, "group": "edges"},
                        {"data": {"id": "367975", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000133961", "idgroup": "367975"}, "group": "edges"},
                        {"data": {"id": "17147", "name": "interologs mapping", "source": "ENSG00000162604", "target": "ENSG00000142192", "idgroup": "17147"}, "group": "edges"},
                        {"data": {"id": "392383", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000132535", "idgroup": "392383"}, "group": "edges"},
                        {"data": {"id": "81771", "name": "interologs mapping", "source": "ENSG00000196549", "target": "ENSG00000142192", "idgroup": "81771"}, "group": "edges"},
                        {"data": {"id": "367974", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000084234", "idgroup": "367974"}, "group": "edges"},
                        {"data": {"id": "367973", "name": "interologs mapping", "source": "ENSG00000127445", "target": "ENSG00000142192", "idgroup": "367973"}, "group": "edges"},
                        {"data": {"id": "42698", "name": "interologs mapping", "source": "ENSG00000186318", "target": "ENSG00000142192", "idgroup": "42698"}, "group": "edges"},
                        {"data": {"id": "367979", "name": "interologs mapping", "source": "ENSG00000171867", "target": "ENSG00000142192", "idgroup": "367979"}, "group": "edges"},
                        {"data": {"id": "367970", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000150991", "idgroup": "367970"}, "group": "edges"},
                        {"data": {"id": "367977", "name": "interologs mapping", "source": "ENSG00000075711", "target": "ENSG00000142192", "idgroup": "367977"}, "group": "edges"},
                        {"data": {"id": "367971", "name": "interologs mapping", "source": "ENSG00000153071", "target": "ENSG00000142192", "idgroup": "367971"}, "group": "edges"},
                        {"data": {"id": "197687", "name": "interologs mapping", "source": "ENSG00000163697", "target": "ENSG00000142192", "idgroup": "197687"}, "group": "edges"},
                        {"data": {"id": "367976", "name": "interologs mapping", "source": "ENSG00000166313", "target": "ENSG00000142192", "idgroup": "367976"}, "group": "edges"},
                        {"data": {"id": "262595", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000100083", "idgroup": "262595"}, "group": "edges"},
                        {"data": {"id": "367966", "name": "interologs mapping", "source": "ENSG00000148082", "target": "ENSG00000142192", "idgroup": "367966"}, "group": "edges"},
                        {"data": {"id": "15760", "name": "interologs mapping", "source": "ENSG00000034053", "target": "ENSG00000142192", "idgroup": "15760"}, "group": "edges"},
                        {"data": {"id": "367965", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000142192", "idgroup": "367965"}, "group": "edges"},
                        {"data": {"id": "367967", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000121653", "idgroup": "367967"}, "group": "edges"},
                        {"data": {"id": "482169", "name": "interologs mapping", "source": "ENSG00000113108", "target": "ENSG00000142192", "idgroup": "482169"}, "group": "edges"},
                        {"data": {"id": "349489", "name": "interologs mapping", "source": "ENSG00000214575", "target": "ENSG00000142192", "idgroup": "349489"}, "group": "edges"},
                        {"data": {"id": "34294", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000158747", "idgroup": "34294"}, "group": "edges"},
                        {"data": {"id": "481584", "name": "interologs mapping", "source": "ENSG00000138449", "target": "ENSG00000142192", "idgroup": "481584"}, "group": "edges"},
                        {"data": {"id": "426683", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000171603", "idgroup": "426683"}, "group": "edges"},
                        {"data": {"id": "404109", "name": "interologs mapping", "source": "ENSG00000142192", "target": "ENSG00000173406", "idgroup": "404109"}, "group": "edges"}];
            var nodes=[];
            var elements=[];
            $.ajax({
                dataType: "json",
                async: false,
                type: "GET",
                url: "http://www.innatedb.com/cerebralLocalizationWS.do",
                data: 'xref=Ensembl&ids=' + ensemblIds,
                success: function(data)
                {
                    for (d in data) {
                        var obj = {
                            data: {
                                id: d,
                                name: genes[d],
                                localization: data[d]
                            },
                            group: "nodes"
                        };
                        nodes.push(obj)
                        //console.log(JSON.stringify(obj));

                    }
                    elements=nodes.concat(edges);
                },
                error: function(jqXHR, textStatus, errorThrown)
                {
                    console.log(errorThrown);
                }
            });
            $(loadCy = function() {

                $('#cy').cytoscape({
                    layout: options,
                    showOverlay: false,
                    zoom: 1,
                    style: cerebral_style,
                    elements: elements,
                    ready: function() {
                        cy = this;
                        cerebral_ready(cy);
                    }
                });
            });
            $(window).resize(function() {
                loadCy();
            });

        </script>  


    </body>
</html>
